package com.demo.fork.complate;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author : YU.TAN
 * @date : 2021/8/20 17:31
 */
public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture.runAsync(()-> System.out.println("this demo"));

        CompletableFuture<String> stringCompletableFuture = CompletableFuture.supplyAsync(() -> "this returnA");
        CompletableFuture<String> apply = stringCompletableFuture.thenApply(r -> {
            return r + ";two";
        });
        System.out.println( apply.get());

        CompletableFuture<String> stringCompletableFuture1 = stringCompletableFuture.thenCompose(r -> {
            return CompletableFuture.supplyAsync(() -> "yes" + r);
        });
        System.out.println(stringCompletableFuture1.get());


    }
}
